package com.bvgol.quartzDemo.config;

import com.bvgol.quartzDemo.job.HelloJob;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import static org.quartz.SimpleScheduleBuilder.simpleSchedule;

@Component
public class HelloJobDetailConfig {

    @Bean
    public JobDetail helloJobDetail(){
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
                .withIdentity("helloJob")
                .storeDurably()
                .usingJobData("data", "保密信息")
                .build();
        return jobDetail;
    }

    @Bean
    public Trigger helloJobTrigger(){
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("helloTrigger")
                .forJob("helloJob")
                .withSchedule(simpleSchedule()
                        .withIntervalInSeconds(3) //控制执行间隔时间
                        .repeatForever())
                .build();

        return trigger;
    }
}
